function [p,ai] = proddfl(sd,md,id,fd,lcd,rv,cpn,yld,per,basis)
%PRODDFL Price with odd first and last periods and settlement in first period.
%   Rreturns the price P and accrued interest AI of a security with odd
%   first and last periods and the settlement date in the first period.
%
%   [P,AI] = PRODDFL(SD,MD,ID,FD,LCD,RV,CPN,YLD)
%   [P,AI] = PRODDFL(SD,MD,ID,FD,LCD,RV,CPN,YLD,PER)
%   [P,AI] = PRODDFL(SD,MD,ID,FD,LCD,RV,CPN,YLD,PER,BASIS)
%
%   Enter dates as serial date numbers or date strings.
%
%   Inputs:
%       SD      -  Settlement date
%       MD      -  Maturity date
%       ID      -  Issue date
%       FD      -  First coupon date
%       LCD     -  Last coupon date
%       RV      -  Par value
%       CPN     -  Coupon rate
%       YLD     -  Annual yield
%
%   Optional Inputs:
%       PER     - the number of coupon periods per year
%                  1 - annual
%                  2 - semi-annual (default)
%                  3 - three times per year
%                  4 - quarterly
%                  6 - bi-monthly
%                 12 - monthly
%
%       BASIS   -  the day-count basis:
%                  0 = actual/actual (default)
%                  1 = 30/360 SIA
%                  2 = actual/360
%                  3 = actual/365
%                  4 = 30/360 PSA
%                  5 = 30/360 ISDA
%                  6 = 30E/360
%                  7 = actual/365 Japanese
%                  8 - actual/actual ISMA
%                  9 - actual/360 ISMA
%                 10 - actual/365 ISMA
%                 11 - 30/360 ISMA
%                 12 - actual/365 ISDA
%
%   Using the following data,
%
%       SD = '03/15/1993'
%       MD = '03/01/2020'
%       ID = '03/01/1993'
%       FD = '07/01/1993'
%       LCD = '01/01/2020'
%       RV = 100
%       CPN = 0.04
%       YLD = 0.0427
%       PER = 2
%       BASIS = 1
%
%   [p,ai] = proddfl(sd,md,id,fd,lcd,rv,cpn,yld,per,basis)
%
%   returns p = 95.71 and ai = 0.16.
%
%   See also PRODDF, PRODDL, PRBOND, YLDBOND.
%
%   Reference: Mayle, Standard Securities Calculation Methods, Volumes
%              I-II, 3rd edition.  Formulas 16, 17, 18, 19.

% Copyright 1995-2006 The MathWorks, Inc.
% $Revision: 1.7.2.8 $   $Date: 2007/11/07 18:29:57 $

if nargin < 10
    basis = 0;
end
if nargin < 9
    per = 2;
end
if nargin < 8
    error('finance:proddfl:notEnoughInputs',...
        'Missing one of SD, MD, ID, FD, LCD, RV, CPN, and YLD.')
end

if any(~isvalidbasis(basis))
    error('finance:proddfl:invalidBasis',...
        'Invalid day count basis specified.');
end

if any(any(ischar(sd) || ischar(md) || ischar(id) || ...
        ischar(fd) || ischar(lcd)))
    sd = datenum(sd);
    md = datenum(md);
    id = datenum(id);
    fd = datenum(fd);
    lcd = datenum(lcd);
end

if length(sd) == 1
    sd = sd*ones(size(md));
end

if length(md) == 1
    md = md*ones(size(sd));
end

if length(id) == 1
    id = id*ones(size(sd));
end

if length(fd) == 1
    fd = fd*ones(size(sd));
end

if length(lcd) == 1
    lcd = lcd*ones(size(sd));
end

if length(rv) == 1
    rv = rv*ones(size(sd));
end

if length(cpn) == 1
    cpn = cpn*ones(size(sd));
end

if length(yld) == 1
    yld = yld*ones(size(sd));
end

if length(per) == 1
    per = per*ones(size(sd));
end

if length(basis) == 1
    basis = basis*ones(size(sd));
end

if checksiz([size(sd);size(md);size(id);size(fd);size(lcd);size(rv);...
        size(cpn);size(yld);size(per);size(basis)],mfilename)
    return
end

p = zeros(size(sd));
ai = p;
for i = 1:length(sd(:));
    d = [];
    if checkrng(str2mat('sd','lcd','cpn','yld','per'),...
            [sd(i),lcd(i),cpn(i),yld(i),per(i)],...
            [id(i) fd(i) 0 0 0],[fd(i) md(i) inf inf inf],...
            str2mat('id','fd','inf','inf','0'),...
            str2mat('fd','md','inf','inf','inf'),['e';'e';'e';'e';'l'],...
            ['e';'e';'l';'l';'l'],mfilename)
        return
    end
    if checktyp('per',per(i),'int',mfilename)
        return;
    end
end     

[p,ai] = bndprice(yld,cpn,sd,md,per,basis,[],id,fd,lcd,[],rv);

% [EOF] 
